import { getInfo, setInfo } from '@/utils/storage'
import { getUserInfoService } from '@/api/user'
export default ({
  namespaced: true,
  state: {
    // 用户个人信息
    userInfo: getInfo(),
    baseInfo: {
      userEmail: '',
      nickname: '',
      gender: '',
      avatar: '',
      introduce: ''
    }
  },
  mutations: {
    setUserInfo (state, newUserInfo) {
      state.userInfo = newUserInfo
      setInfo(newUserInfo)
    },
    setBaseInfo (state, newInfo) {
      state.baseInfo = newInfo
    },
    setAvatar (state, newAvatar) {
      state.baseInfo.avatar = newAvatar
    }
  },
  getters: {
    getBaseInfo (state) {
      return state.baseInfo
    },
    getAvatar (state) {
      return state.baseInfo.avatar
    }
  },
  actions: {
    async getBaseInfoService (context) {
      const res = await getUserInfoService()
      context.commit('setBaseInfo', res.data)
    }
  }
})
